package org.starsource.forum.shared.util;

public class ImageContainerSupport {
	private int imageWidth, imageHeight;
	private int containerWidth, containerHeight;
	private int scaleWidth, scaleHeight;
	
	public int getImageWidth() {
		return this.imageWidth;
	}
	public void setImageWidth(int imageWidth) {
		this.imageWidth = imageWidth;
	}
	
	public int getImageHeight() {
		return this.imageHeight;
	}
	public void setImageHeight(int imageHeight) {
		this.imageHeight = imageHeight;
	}
	public void setImageSize(int imageWidth, int imageHeight) {
		setImageWidth(imageWidth);
		setImageHeight(imageHeight);
	}
	
	public int getContainerWidth() {
		return this.containerWidth;
	}
	public void setContainerWidth(int containerWidth) {
		this.containerWidth = containerWidth;
	}
	
	public int getContainerHeight() {
		return this.containerHeight;
	}
	public void setContainerHeight(int containerHeight) {
		this.containerHeight = containerHeight;
	}
	public void setContainerSize(int containerWidth, int containerHeight) {
		setContainerWidth(containerWidth);
		setContainerHeight(containerHeight);
	}
	public int getScaleWidth() {
		return this.scaleWidth;
	}
	
	public int getScaleHeight() {
		return this.scaleHeight;
	}
	
	public ImageContainerSupport() {
		
	}
	public ImageContainerSupport(int imageWidth, int imageHeight, int containerWidth, int containerHeight) {
		setImageSize(imageWidth, imageHeight);
		setContainerSize(containerWidth, containerHeight);
	}
	
	public void calculateScale() {
		if (this.containerWidth >= this.imageWidth && this.containerHeight >= this.imageHeight) {
			this.scaleWidth = this.imageWidth;
			this.scaleHeight = this.imageHeight;
//			Window.alert("1.IMAGE("+this.getImageWidth()+","+this.getImageHeight()+ ") " +
//					"CONTAINER(" + this.getContainerWidth() + "," + this.getContainerHeight() + ") " +
//					"SCALE(" + this.getScaleWidth() + "," + this.getScaleHeight() + ")");
//			logger.debug("Image can be hold in container without scale");
			return;
		}
		
		if (containerWidth * imageHeight >= containerHeight * imageWidth) {
			this.scaleHeight = this.containerHeight;
			this.scaleWidth = this.imageWidth * this.scaleHeight / this.imageHeight;
//			Window.alert("2.IMAGE("+this.getImageWidth()+","+this.getImageHeight()+ ") " +
//					"CONTAINER(" + this.getContainerWidth() + "," + this.getContainerHeight() + ") " +
//					"SCALE(" + this.getScaleWidth() + "," + this.getScaleHeight() + ")");
//			logger.debug("set Scale height to container height");
			return;
		}
		
		this.scaleWidth = this.containerWidth;
		this.scaleHeight = this.imageHeight * this.scaleWidth / this.imageWidth;
//		Window.alert(".IMAGE("+this.getImageWidth()+","+this.getImageHeight()+ ") " +
//				"CONTAINER(" + this.getContainerWidth() + "," + this.getContainerHeight() + ") " +
//				"SCALE(" + this.getScaleWidth() + "," + this.getScaleHeight() + ")");
//		logger.debug("set Scale width to container width");
	}
	
}
